// pages/personal/index.js
import api from '../../utils/api.js'
const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		array: [{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/order.png",
				iconText: '我的订单',
				urlLink: '/pages/myOrder/index/index',
				event: 'url',
			},
			// {
			// 	iconSrc: "https://cdn.oss.dgddaijia.com/icons/integral_mall.png",
			// 	iconText: '积分商城',
			// 	urlLink: '/pages/integralMall/index/index',
			// event: 'url',
			// },
			// {
			// 	iconSrc: "https://cdn.oss.dgddaijia.com/icons/card_voucher.png",
			// 	iconText: '我的卡券',
			// 	urlLink: '/pages/myCardVoucher/myCardVoucher',
			// 	isShow: true,
			// event: 'url',
			// },
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/charge_standard.png",
				iconText: '收费标准',
				urlLink: '/pages/personal/ratesNorm/ratesNorm',
				event: 'url',
			},
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/customer_service.png",
				iconText: '客服热线',
				urlLink: '/pages/serHotline/serHotline',
				event: 'url',
			},
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/driving_service.png",
				iconText: '代驾服务协议',
				urlLink: '/pages/serAgreement/serAgreement',
				event: 'url',
			},
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/promotion_code.png",
				iconText: '我的推广',
				urlLink: '/pages/personal/myPromote/index/index?type=' + 1,
				event: 'url',
			},
			// {
			// 	iconSrc: "https://cdn.oss.dgddaijia.com/icons/counseling_center.png",
			// 	iconText: '资讯中心',
			// 	urlLink: '/pages/personal/counseCenter/index/index',
			// 	isShow: true,
			// event: 'url',
			// },
			// {
			// 	iconSrc: "https://cdn.oss.dgddaijia.com/icons/complaint_center.png",
			// 	iconText: '投诉中心',
			// 	urlLink: '/pages/personal/complaintsCenter/index/index',
			// 	isShow: true,
			// event: 'url',
			// },
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/scan.png",
				iconText: '扫一扫',
				urlLink: '/pages/personal/ratesNorm/ratesNorm',
				event: 'event',
				eventName: "scanEvent"
			},
			{
				iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/message.png",
				iconText: '消息',
				urlLink: '/pages/messageList/messageList',
				event: 'url',
            },
            {
				iconSrc: "eye-o",
				iconText: '审车服务',
				urlLink: '/pages/personal/checkCar/index/index',
				event: 'url',
			},
		],
		isShow: true,
		userInfo: null, //用户信息
		account: null, //用户余额
		userQx: '', //用户权限，控制显示的内容
		userWallet: [], //用户余额内容
		score: '', //用户积分
	},
	goPersonal() {
		wx.navigateTo({
			url: '/pages/personInfo/personInfo',
		})
	},
	scanEvent() {
		//打开扫一扫
		var that = this;
		app.commonScan(function(res) {
			app.commonInit(res);
		})
	},
	goMessage() {
		//去消息页面
		wx.navigateTo({
			url: '/pages/messageList/messageList',
		})
	},
	logout() {
		// 退出登录
		app.logout()
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		// 账户类型    1代表用户   2代表代驾  3代表省代理 4代表市代理  
		// 5代表区代理  6代表围栏代理  7代表网约车司机  8代表网约车用户  
		// 9代表骑手  10代表商家  11代表外卖用户  12业务    13代驾商户
		var that = this
	},

	onShow() {
		var that = this;
		if (wx.getStorageSync('isLogin')) {
			//菜单生成
			var userQx = wx.getStorageSync('userAllInfo').type
			for (var i in this.data.array) {
				if (Number(this.data.array[i].type) > 0) {
					for (var j in userQx) {
						if (Number(this.data.array[i].type) === Number(userQx[j])) {
							delete userQx[j];
						}
					}
				}
			}
			if (wx.getStorageSync('isLogin')) {
				if (userQx.indexOf('12') != -1) {
					that.data.array.push({
						iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/business-user.png",
						iconText: '业务收益',
						urlLink: '/pages/personal/networkData/networkData?type=' + 12,
						event: 'url',
						isShow: true,
						type: 12
					})
				}
				if (userQx.indexOf('6') != -1) {
					var obj = {
						iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/money.png",
						iconText: '网点收益',
						urlLink: '/pages/personal/networkData/networkData?type=' + 6,
						event: 'url',
						isShow: true,
						type: 6
					}
					that.data.array.push(obj)
				}
				if (userQx.indexOf('4') != -1) {
					var obj = {
						iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/money.png",
						iconText: '市代理收益',
						urlLink: '/pages/personal/networkData/networkData?type=' + 4,
						event: 'url',
						isShow: true,
						type: 4
					}
					that.data.array.push(obj)
				}
				if (userQx.indexOf('3') != -1) {
					var obj = {
						iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/money.png",
						iconText: '省代理收益',
						urlLink: '/pages/personal/networkData/networkData?type=' + 3,
						event: 'url',
						isShow: true,
						type: 3
					}
					that.data.array.push(obj)
				}
				if (userQx.indexOf('13') != -1) {
					var obj = {
						iconSrc: "https://cdn.oss.dgddaijia.com/icons/new_logo/shop.png",
						iconText: '商家收益',
						urlLink: '/pages/personal/networkData/networkData?type=' + 13,
						event: 'url',
						isShow: true,
						type: 13
					}
					that.data.array.push(obj)
				}
			}
			that.setData({
				array: that.data.array
			})
			that.setData({
				userInfo: app.globalData.userAllInfo
			})
			var userInfo = wx.getStorageSync('userAllInfo')
			if (userInfo.wallet.length == 0) {
				var userWallet = [{
					id: null,
					user_id: userInfo.id,
					type: 1,
					account: 0.00,
					score: 0,
					commission: 0
				}]
				that.setData({
					userWallet: userWallet,
				})
			} else {
				var userWallet = userInfo.wallet
				userWallet.map((item, index) => {
					if (item.type == 1) {
						that.data.userWallet.push(item)
					}
				})
			}
			that.setData({
				userWallet: that.data.userWallet,
			})
		} else {
			wx.showToast({
				title: '请先登录',
				icon: 'none'
			})
			setTimeout(function(res) {
				wx.navigateTo({
					url: '/pages/login/login'
				})
			}, 200)
		}
	},

	goMyAccount() {
		wx.navigateTo({
			url: '/pages/personal/myAccount/index/index?type=' + 1 + '&msgType=' + 'account',
		})
	},

	goMyScores() {
		wx.navigateTo({
			url: '/pages/personal/myAccount/index/index?type=' + 1 + '&msgType=' + 'score',
		})
	}
})
